package com.community.itelligentcommunity.community.communityProperty.controller;

import com.community.itelligentcommunity.common.base.constant.SystemStaticConst;
import com.community.itelligentcommunity.common.base.controller.GenericController;
import com.community.itelligentcommunity.common.base.service.GenericService;
import com.community.itelligentcommunity.community.communityProperty.entity.PatrolControlInf;
import com.community.itelligentcommunity.community.communityProperty.entity.QueryPatrolControl;
import com.community.itelligentcommunity.community.communityProperty.service.PatrolControlService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/patrolManagerControl")
public class PatrolManagerControl extends GenericController <PatrolControlInf, QueryPatrolControl> {

    @Autowired
    private PatrolControlService pillControlService;

    @Override
    protected GenericService<PatrolControlInf, QueryPatrolControl> getService() {
        return pillControlService;
    }

    /**
     *功能描述：获取文档类型的下拉框数据
     */
    @RequestMapping(value = "/updateTime",method = RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public Map<String,Object> getType(PatrolControlInf qd){
        Map<String,Object> result = new HashMap<String, Object>();
        qd = getService().get(qd);
        String str="";
        Date dt = new Date();
        //最后的aa表示“上午”或“下午”    HH表示24小时制    如果换成hh表示12小时制
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        str=sdf.format(dt);
        if(qd.getRecordA()== null){
            qd.setRecordA(str);
        }else{
            if(qd.getRecordB()== null){
                qd.setRecordB(str);
            }else{
                if(qd.getRecordC()== null){
                    qd.setRecordC(str);
                }else{
                    if(qd.getRecordD()== null){
                        qd.setRecordD(str);
                    }else{
                        result.put(SystemStaticConst.RESULT,SystemStaticConst.SUCCESS);
                        result.put(SystemStaticConst.MSG,"该条路线已经巡逻完毕，无需打卡！");
                    }
                }
            }
        }
        boolean success= pillControlService.updateManager(qd);

        if(success==true){
            result.put(SystemStaticConst.RESULT,SystemStaticConst.SUCCESS);
            result.put(SystemStaticConst.MSG,"更新数据成功！");
        }else{
            result.put(SystemStaticConst.RESULT,SystemStaticConst.FAIL);
            result.put(SystemStaticConst.MSG,"更新数据失败！");
        }
        return result;
    }
}
